package 代码记录.校招笔试真题.笔试真题_2022.去哪儿网;

import java.util.Arrays;
import java.util.EventListener;

public class Test3 {
    /**
     * 这道题很想知道哪不对！！！！！
     */
    public static void main(String[] args) {
//        String inHand = "SA SK SQ SJ S10 H10 C9";
//        String inHand = "SK SQ SJ S10 S9";
        String inHand = "S4 S4 S4 S4 S9";
        String res = showDown(inHand);
        System.out.println(res);
    }
    /**
     扑克牌有四种花色：S：黑桃  H：红心  C：草花   D：方片
     输入："SA SK SQ SJ S10 H10 C9" --- > AKQJ10 109
     输出："HuangJiaTongHuaShun"  --得到的结果为这些牌中排序最靠前的类型

     */
    public static String showDown (String inHand) {
        String res = "";
        String[] arr = inHand.split(" ");
        //需要记录：花色数、顺序数、连续数
        char[] huaSe = new char[5];
        char[] temp = new char[5];
        for(int i = 0;i < 5;i++){
            huaSe[i] = arr[i].charAt(0);
            if(arr[i].length() == 3) {
                temp[i] = 'H';
            }else{
                temp[i] = arr[i].charAt(1);
            }
        }
        String pai = "";
        for(int i = 0;i < 5;i++){
            pai += temp[i];
        }
        int[] count = new int[4];
        for(int i = 0;i < 5;i++){
            if(huaSe[i] == 'S'){
                count[0]++;
            }else if(huaSe[i] == 'H'){
                count[1]++;
            }else if(huaSe[i] == 'C'){
                count[2]++;
            }else if(huaSe[i] == 'D'){
                count[3]++;
            }
        }
        String moban = "AKQJH98765432";
        if(pai.equals("AKQJH")){
            res = "HuangJiaTongHuaShun";//皇家同花顺
            return res;
        }
        for(int i = 0;i < moban.length() - 5;i++){
            if(pai.equals(moban.substring(i,i + 5))){
                for(int j = 0;j < 4;j++){
                    if(count[j] == 5){
                        res = "TongHuaShun";//2同花顺
                        return res;
                    }
                }
            }
        }
        for(int i = 0;i < 4;i++){
            if(count[i] == 4){
                res = "SiTiao";//四条
                return res;
            }
        }
        boolean h = false;
        boolean l = false;
        for(int i = 0;i < 4;i++){
            if(count[i] == 3) h = true;
            if(count[i] == 2) l = true;
        }
        if(h && l){
            res = "HuLu";//葫芦
            return res;
        }
        for(int i = 0;i < 5;i++){
            if(count[i] == 5){
                res = "TongHua";
                return res;
            }
        }
        String mp = "KQJH98765432A";
        for(int i = 0;i < mp.length() - 5;i++){
            if(pai.equals(mp.substring(i,i + 5))){
                res = "ShunZi";
                return res;
            }
        }
        return "SanTiao";
    }
}
